/*
 * Copyright (C) 2016 Facishare Technology Co., Ltd. All Rights Reserved.
 */
package com.android.floatwindowpermission;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.android.SharedPreUtil;
import com.android.net.OkGo;
import com.android.net.callback.StringCallback;
import com.android.net.model.Progress;
import com.android.net.model.Response;
import com.android.permission.FloatWindowManager;
import com.google.gson.Gson;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import okhttp3.MediaType;

/**
 * Description:
 *
 * @author zhaozp
 * @since 2016-10-17
 */

public class FloatWindowActivity extends Activity {


    EditText name;

    EditText pas;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        name=findViewById(R.id.name);
        pas=findViewById(R.id.pas);
        findViewById(R.id.btn_show_or_apply).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Map<String,String> map=new HashMap<>();
                map.put("id",pas.getText().toString());
                Gson gson=new Gson();
                OkGo.<String>post("http://"+pas.getText().toString()+"/getpk")
                        .tag(this)
                        // .upJson("{\"id\": \"M20180725017\"}")
                        .upJson(gson.toJson(map))
                        .execute(new StringCallback() {
                            @Override
                            public void onSuccess(Response<String> response) {
                                BaseConstants.Url="http://"+pas.getText().toString();
                                BaseConstants.ID=name.getText().toString();
                                FloatWindowManager.getInstance().applyOrShowFloatWindow(FloatWindowActivity.this);
                                Log.e("loan222",response.body());
                            }

                            @Override
                            public void onError(Response<String> response) {
                            }

                            @Override
                            public void uploadProgress(Progress progress) {
                                Log.e("data",progress.currentSize+"11");
                            }
                        });

            }
        });

        findViewById(R.id.btn_dismiss).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FloatWindowManager.getInstance().dismissWindow();
            }
        });
    }

}
